package com.shixj.demo.exchanger;

import java.util.ArrayList;
import java.util.concurrent.Exchanger;

/**
 * Created by shixj on 2017/9/26.
 */
public class Odd implements Runnable {
    final Exchanger<ArrayList<Integer>> exchanger;
    private final ArrayList<Integer> odd = new ArrayList<Integer>(5);
    public Odd(Exchanger<ArrayList<Integer>> exchanger) {
        this.exchanger = exchanger;
    }

    @Override
    public void run() {
        for(int i=1;i<10;i=i+2){
            odd.add(i);
        }
        System.out.println("奇数列（原数列）："+odd);
        try{
            System.out.println("奇数列（现数列）："+exchanger.exchange(odd));
        }catch (InterruptedException e){
            e.printStackTrace();
        }

    }
}
